from core.host import Host_Handler
from conf.settings import SEQ01
import sys
import requests
import json


class main_command(object):

    def __init__(self, sys_argv):
        self.method_list = [
            'host_info',
        ]

        self.sys_argv = sys_argv

        self.message = u"""
        Please input the argument:
        host_info: get host all info and submit data to server. 
        """

        if (len(sys_argv) < 2) or (self.sys_argv[1] not in self.method_list):
            sys.exit(self.message)

        if self.sys_argv[1] == 'host_info':
            self.host_info()


    def send_request(self, url, method, data):
        headers = {"Content-type": "application/json"}

        res = None
        if method in ('get', "GET"):
            try:
                res = requests.get(url, data=json.dumps(data), headers=headers)
                return res
            except Exception as e:
                print(e)

        if method in ('post', 'POST'):
            try:
                res = requests.post(url, data=json.dumps(data), headers=headers)
                return res
            except Exception as e:
                print(e)

        return res

    def host_info(self):
        host_handler = Host_Handler()
        data = host_handler.host_info()
        print(data)